<%--
  Created by IntelliJ IDEA.
  User: 郝大哥
  Date: 2021/11/26
  Time: 9:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - jqGird</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="<%=request.getContextPath()%>/resource/favicon.ico"> <link href="<%=request.getContextPath()%>/resource/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/resource/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <!-- jqgrid-->
    <link href="<%=request.getContextPath()%>/resource/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">

    <link href="<%=request.getContextPath()%>/resource/css/animate.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/resource/css/style.css?v=4.1.0" rel="stylesheet">

    <style>
        /* Additional style to fix warning dialog position */

        #alertmod_table_list_2 {
            top: 900px !important;
        }
    </style>

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <h4> <button data-toggle="button" class="btn btn-primary btn-outline" type="button" id="init">初始化国内疫情</button></h4>
                    <div class="jqGrid_wrapper">
                        <table id="table_list_1"></table>
                        <div id="pager_list_1"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <h4> <button data-toggle="button" class="btn btn-primary btn-outline" type="button" id="initCity">初始化地级市疫情</button></h4>
                    <div class="jqGrid_wrapper">
                        <table id="table_list_2"></table>
                        <div id="pager_list_2"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="<%=request.getContextPath()%>/resource/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=request.getContextPath()%>/resource/js/bootstrap.min.js?v=3.3.6"></script>



<!-- Peity -->
<script src="<%=request.getContextPath()%>/resource/js/plugins/peity/jquery.peity.min.js"></script>

<!-- jqGrid -->
<script src="<%=request.getContextPath()%>/resource/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="<%=request.getContextPath()%>/resource/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>

<!-- 自定义js -->
<script src="<%=request.getContextPath()%>/resource/js/content.js?v=1.0.0"></script>

<!-- Page-Level Scripts -->
<script>
    $(document).ready(function () {
        $.ajax({
            url:"https://interface.sina.cn/news/wap/fymap2020_data.d.json",
            dataType:"jsonp",
            success:function(res){
                console.log(res);
               $.jgrid.defaults.styleUI = 'Bootstrap';
               // Examle data for jqGrid
                var myData=[];
                var myData1=new Array();//创建一个新数组
                var province=res.data.list;
                for(var i=0;i<province.length;i++){
                    myData[i]={"name":province[i].name,"value":province[i].value,"cureNum":province[i].cureNum,
                        "deathNum":province[i].deathNum,"econNum":province[i].econNum,"time":res.data.mtime.substr(0,10)};
                    for(var j=0;j<province[i].city.length;j++){
                        myData1.push({"provinceName":province[i].name,"cityName":province[i].city[j].mapName,"conNum":province[i].city[j].conNum,
                        "cureNum":province[i].city[j].cureNum,"deathNum":province[i].city[j].deathNum,"econNum":province[i].city[j].econNum,"time":res.data.mtime.substr(0,10)});
                    }
                }
               $("#table_list_1").jqGrid({
                   data: myData,
                   datatype: "local",
                   height: 250,
                   autowidth: true,
                   shrinkToFit: true,
                   rowNum: 14,
                   rowList: [10, 20, 30],
                   colNames: [ '省份/直辖市', '确诊人数', '治愈人数', '死亡人数', '未痊愈人数','时间'],
                   colModel: [
                       {
                           name: 'name',
                           index: 'name',
                           width: 60
                       },
                       {
                           name: 'value',
                           index: 'value',
                           width: 80,
                           sorttype: "int",
                       },
                       {
                           name: 'cureNum',
                           index: 'cureNum',
                           width: 100,
                           sorttype: "int"
                       },
                       {
                           name: 'deathNum',
                           index: 'deathNum',
                           width: 80,
                           sorttype: "int"
                       },
                       {
                           name: 'econNum',
                           index: 'econNum',
                           width: 80,
                           align: "right",
                           sorttype: "int"
                       },
                       {
                           name: 'time',
                           index: 'time',
                           width: 90,
                           sorttype: "date",
                           formatter: "date"
                       }
                   ],
                   pager: "#pager_list_1",
                   viewrecords: true,
                   caption: "国内省份数据",
                   hidegrid: false
               });
                $("#table_list_2").jqGrid({
                    data: myData1,
                    datatype: "local",
                    height: 250,
                    autowidth: true,
                    shrinkToFit: true,
                    rowNum: 14,
                    rowList: [10, 20, 30],
                    colNames: [ '省份/直辖市', '地级市','确诊人数', '治愈人数', '死亡人数', '未痊愈人数','时间'],
                    colModel: [
                        {
                            name: 'provinceName',
                            index: 'provinceName',
                            width: 100
                        },
                        {
                            name: 'cityName',
                            index: 'cityName',
                            width: 100
                        },
                        {
                            name: 'conNum',
                            index: 'conNum',
                            width: 80,
                            sorttype: "int"
                        },
                        {
                            name: 'cureNum',
                            index: 'cureNum',
                            width: 80,
                            sorttype: "int"
                        },
                        {
                            name: 'deathNum',
                            index: 'deathNum',
                            width: 80,
                            sorttype: "int"
                        },
                        {
                            name: 'econNum',
                            index: 'econNum',
                            width: 80,
                            align: "right",
                            sorttype: "int"
                        },
                        {
                            name: 'time',
                            index: 'time',
                            width: 100,
                            sorttype: "date",
                            formatter: "date"
                        }
                    ],
                    pager: "#pager_list_2",
                    viewrecords: true,
                    caption: "国内地级市数据",
                    hidegrid: false
                });
               // Add responsive to jqGrid
               $(window).bind('resize', function () {
                   var width = $('.jqGrid_wrapper').width();
                   $('#table_list_1').setGridWidth(width);
                   $('#table_list_2').setGridWidth(width);
               });
               $("#init").click(function(){
                   var json=JSON.stringify(myData);
                   alert(json);
                   $.ajax({
                       url:"<%=request.getContextPath()%>/yq/initToDb?json="+json,//请求后台路径
                       type:"get",//请求方式
                       success:function (){
                           alert("数据加载完毕！！！！");
                       }
                   });
               });
               $("#initCity").click(function(){
                   var cityJson=JSON.stringify(myData1);
                   $.ajax({
                       url:"<%=request.getContextPath()%>/yq/initCityToDb",//请求后台路径
                       type:"post",//请求方式
                       contentType:'application/json;charset=UTF-8',//关键是要加上这行
                       data:cityJson,
                       success:function (){
                           alert("数据加载完毕！！！！");
                       }
                   });
               });
           }
        });
    });
</script>
</body>
</html>

